package com.interesting.examsystem.common.response;

import org.springframework.http.HttpStatus;

/**
 * @author ：ZXY
 * @date ：Created in 2021/2/22 16:36
 * @description：返回结果生成
 * @modified By：`
 * @version: 1.0
 */
public class ResultGenerator {
    private static final String DEFAULT_OK_MESSAGE = "OK";
    private static final String DEFAULT_UNAUTHORIZED_MESSAGE = "Need authorized";
    private static final String DEFAULT_METHOD_NOT_ALLOWED_MESSAGE = "Request method incorrect";

    public static Result genOkResult() {
        return (new Result.Builder(Integer.valueOf(HttpStatus.OK.value()))).msg("OK").success(true).build();
    }

    public static Result genOkResult(Object data) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.OK.value()))).msg("OK").success(true).rows(data).build();
    }

    public static Result genOkResult(String msg, Object data) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.OK.value()))).msg(msg).success(true).rows(data).build();
    }

    public static Result genFailedResult(String msg, String resultCode, Object data) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.BAD_REQUEST.value()))).msg(msg).resultCode(resultCode).success(false).rows(data).build();
    }

    public static Result genFailedResult(String msg, String resultCode) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.BAD_REQUEST.value()))).msg(msg).resultCode(resultCode).success(false).build();
    }

    public static Result genFailedResult(String msg) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.BAD_REQUEST.value()))).msg(msg).success(false).build();
    }

    public static Result genMethodErrorResult() {
        return (new Result.Builder(Integer.valueOf(HttpStatus.METHOD_NOT_ALLOWED.value()))).msg("Request method incorrect").success(false).build();
    }

    public static Result genUnauthorizedResult() {
        return (new Result.Builder(Integer.valueOf(HttpStatus.UNAUTHORIZED.value()))).msg("Need authorized").success(false).build();
    }

    public static Result genUnauthorizedResult(String msg, String resultCode) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.UNAUTHORIZED.value()))).msg(msg).resultCode(resultCode).success(false).build();
    }

    public static Result genUnauthorizedResult(String msg) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.UNAUTHORIZED.value()))).msg(msg).success(false).build();
    }

    public static Result genInternalServerErrorResult(String url) {
        return (new Result.Builder(Integer.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value())))
                .msg("API [" + url + "] internal server error. Please call engineer to debug.").success(false).build();
    }
}
